import axios from '@/libs/api.request'
import Qs from 'qs'

/*// 网络请求测试
export const test = (data) => {

  return axios.request({
    url: 'test/test',
    params: data,
    // data: Qs.stringify(data),
    method: 'get'
  })
}
//email测试
export const emailTest = (data) => {
  return axios.request({
    url: 'mail/getCheckCode',
    params: data,
    method: 'post'
  })
}

//登陆注册--查询是否存在相同用户名
export const findByUsername = (data) => {
  return axios.request({
    url: 'regLogin/findByUsername',
    params: data,
    method: 'post'
  })
}*/


export const UserLogin = (data) => {
  return axios.request({
    url: 'User/Login',
    params: data,
    method: 'post'
  })
};

export const UserFindAll = (data) => {
  return axios.request({
    url: 'User/FindAll',
    params: data,
    method: 'post'
  })
};

/**
 * 设备类别
 */

export const DeviceCategoryFindAll = (data) => {
  return axios.request({
    url: 'DeviceCategory/FindAll',
    params: data,
    method: 'post'
  })
};

export const DeviceCategoryFindByCategory = (data) => {
  return axios.request({
    url: 'DeviceCategory/FindByCategory',
    params: data,
    method: 'post'
  })
};

export const DeviceCategoryUpdateById = (data) => {
  return axios.request({
    url: 'DeviceCategory/UpdateById',
    params: data,
    method: 'post'
  })
};

export const DeviceCategoryInsert = (data) => {
  return axios.request({
    url: 'DeviceCategory/Insert',
    params: data,
    method: 'post'
  })
};

export const DeviceCategoryDelete = (data) => {
  return axios.request({
    url: 'DeviceCategory/Delete',
    params: data,
    method: 'post'
  })
};
/**
 * 工艺过程
 */
export const ProcessFindAll = (data) => {
  return axios.request({
    url: 'Process/FindAll',
    params: data,
    method: 'post'
  })
};

export const ProcessFindByCode = (data) => {
  return axios.request({
    url: 'Process/FindByCode',
    params: data,
    method: 'post'
  })
};

export const ProcessUpdateById = (data) => {
  return axios.request({
    url: 'Process/UpdateById',
    params: data,
    method: 'post'
  })
};

export const ProcessInsert = (data) => {
  return axios.request({
    url: 'Process/Insert',
    params: data,
    method: 'post'
  })
};

export const ProcessDelete = (data) => {
  return axios.request({
    url: 'Process/Delete',
    params: data,
    method: 'post'
  })
};

/**
 * 产品
 */
/*
export const ProductFindAll = (data) => {
  return axios.request({
    url: 'Product/FindAll',
    params: data,
    method: 'post'
  })
};

export const ProductFindByCode = (data) => {
  return axios.request({
    url: 'Product/FindByCode',
    params: data,
    method: 'post'
  })
};

export const ProductUpdateById = (data) => {
  return axios.request({
    url: 'Product/UpdateById',
    params: data,
    method: 'post'
  })
};

export const ProductInsert = (data) => {
  return axios.request({
    url: 'Product/Insert',
    params: data,
    method: 'post'
  })
};

export const ProductDelete = (data) => {
  return axios.request({
    url: 'Product/Delete',
    params: data,
    method: 'post'
  })
};*/
/**
 * 原料
 */
export const MaterialFindAll = (data) => {
  return axios.request({
    url: 'Material/FindAll',
    params: data,
    method: 'post'
  })
};

export const MaterialFindByCode = (data) => {
  return axios.request({
    url: 'Material/FindByCode',
    params: data,
    method: 'post'
  })
};

export const MaterialUpdateById = (data) => {
  return axios.request({
    url: 'Material/UpdateById',
    params: data,
    method: 'post'
  })
};

export const MaterialInsert = (data) => {
  return axios.request({
    url: 'Material/Insert',
    params: data,
    method: 'post'
  })
};

export const MaterialDelete = (data) => {
  return axios.request({
    url: 'Material/Delete',
    params: data,
    method: 'post'
  })
};

/**
 * 设备
 */
export const DeviceFindAll = (data) => {
  return axios.request({
    url: 'Device/FindAll',
    params: data,
    method: 'post'
  })
};

export const DeviceFindByCode = (data) => {
  return axios.request({
    url: 'Device/FindByCode',
    params: data,
    method: 'post'
  })
};

export const DeviceUpdateById = (data) => {
  return axios.request({
    url: 'Device/UpdateById',
    params: data,
    method: 'post'
  })
};

export const DeviceInsert = (data) => {
  return axios.request({
    url: 'Device/Insert',
    params: data,
    method: 'post'
  })
};

export const DeviceDelete = (data) => {
  return axios.request({
    url: 'Device/Delete',
    params: data,
    method: 'post'
  })
};

/**
 * 订单管理
 */
export const OrderFindAll = (data) => {
  return axios.request({
    url: 'Order/FindAll',
    params: data,
    method: 'post'
  })
};

export const OrderDelete = (data) => {
  return axios.request({
    url: 'Order/Delete',
    params: data,
    method: 'post'
  })
};

export const OrderInsert = (data) => {
  return axios.request({
    url: 'Order/Insert',
    params: data,
    method: 'post'
  })
};

export const OrderFindByOrderNo = (data) => {
  return axios.request({
    url: 'Order/FindByOrderNo',
    params: data,
    method: 'post'
  })
};

export const OrderUpdateById = (data) => {
  return axios.request({
    url: 'Order/UpdateById',
    params: data,
    method: 'post'
  })
};
/**
 * 订单BOM
 */
export const OrderBomFindAll = (data) => {
  return axios.request({
    url: 'OrderBom/FindAll',
    params: data,
    method: 'post'
  })
};

/**
 * BOM
 */
export const BomFindAll = (data) => {
  return axios.request({
    url: 'Bom/FindAll',
    params: data,
    method: 'post'
  })
};

export const BomInsert = (data) => {
  return axios.request({
    url: 'Bom/Insert',
    params: data,
    method: 'post'
  })
};

export const BomDelete = (data) => {
  return axios.request({
    url: 'Bom/Delete',
    params: data,
    method: 'post'
  })
};
/**
 * 路线
 */
export const RoutingFindAll = (data) => {
  return axios.request({
    url: 'Routing/FindAll',
    params: data,
    method: 'post'
  })
};

export const RoutingFindByCode = (data) => {
  return axios.request({
    url: 'Routing/FindByCode',
    params: data,
    method: 'post'
  })
};

export const RoutingUpdateById = (data) => {
  return axios.request({
    url: 'Routing/UpdateById',
    params: data,
    method: 'post'
  })
};

export const RoutingInsert = (data) => {
  return axios.request({
    url: 'Routing/Insert',
    params: data,
    method: 'post'
  })
};

export const RoutingDelete = (data) => {
  return axios.request({
    url: 'Routing/Delete',
    params: data,
    method: 'post'
  })
};

/**
 *路线 工艺过程
 */
export const RoutingProcessFindAll = (data) => {
  return axios.request({
    url: 'RoutingProcess/FindAll',
    params: data,
    method: 'post'
  })
};

export const RoutingProcessFindById = (data) => {
  return axios.request({
    url: 'RoutingProcess/FindById',
    params: data,
    method: 'post'
  })
};

export const RoutingProcessUpdateById = (data) => {
  return axios.request({
    url: 'RoutingProcess/UpdateById',
    params: data,
    method: 'post'
  })
};

export const RoutingProcessInsert = (data) => {
  return axios.request({
    url: 'RoutingProcess/Insert',
    params: data,
    method: 'post'
  })
};

export const RoutingProcessDelete = (data) => {
  return axios.request({
    url: 'RoutingProcess/Delete',
    params: data,
    method: 'post'
  })
};

/**
 *
 */

export const StockFindAll = (data) => {
  return axios.request({
    url: 'Stock/FindAll',
    params: data,
    method: 'post'
  })
};

/**
 * 物料类型
 */
export const MaterialTypeFindAll = (data) => {
  return axios.request({
    url: 'MaterialType/FindAll',
    params: data,
    method: 'post'
  })
};

export const MaterialTypeFindById = (data) => {
  return axios.request({
    url: 'MaterialType/FindById',
    params: data,
    method: 'post'
  })
};

export const MaterialTypeInsert = (data) => {
  return axios.request({
    url: 'MaterialType/Insert',
    params: data,
    method: 'post'
  })
};

export const MaterialTypeUpdateById = (data) => {
  return axios.request({
    url: 'MaterialType/UpdateById',
    params: data,
    method: 'post'
  })
};

export const MaterialTypeDelete = (data) => {
  return axios.request({
    url: 'MaterialType/Delete',
    params: data,
    method: 'post'
  })
};


/**
 *原材料材质分类类别
 */
export const MaterialClassificationFindAll = (data) => {
  return axios.request({
    url: 'MaterialClassification/FindAll',
    params: data,
    method: 'post'
  })
};

export const MaterialClassificationFindByCode = (data) => {
  return axios.request({
    url: 'MaterialClassification/FindByCode',
    params: data,
    method: 'post'
  })
};

export const MaterialClassificationInsert = (data) => {
  return axios.request({
    url: 'MaterialClassification/Insert',
    params: data,
    method: 'post'
  })
};

export const MaterialClassificationUpdateByCode = (data) => {
  return axios.request({
    url: 'MaterialClassification/UpdateByCode',
    params: data,
    method: 'post'
  })
};

export const MaterialClassificationDeleteByCode = (data) => {
  return axios.request({
    url: 'MaterialClassification/DeleteByCode',
    params: data,
    method: 'post'
  })
};

export const MaterialClassificationDelete = (data) => {
  return axios.request({
    url: 'MaterialClassification/Delete',
    params: data,
    method: 'post'
  })
};

/**
 *原材料材质分类
 */
export const CategoryFindAll = (data) => {
  return axios.request({
    url: 'Category/FindAll',
    params: data,
    method: 'post'
  })
};

export const CategoryFindByCode = (data) => {
  return axios.request({
    url: 'Category/FindByCode',
    params: data,
    method: 'post'
  })
};

export const CategoryInsert = (data) => {
  return axios.request({
    url: 'Category/Insert',
    params: data,
    method: 'post'
  })
};

export const CategoryUpdateByCode = (data) => {
  return axios.request({
    url: 'Category/UpdateByCode',
    params: data,
    method: 'post'
  })
};

export const CategoryDeleteByCode = (data) => {
  return axios.request({
    url: 'Category/DeleteByCode',
    params: data,
    method: 'post'
  })
};

export const CategoryDelete = (data) => {
  return axios.request({
    url: 'Category/Delete',
    params: data,
    method: 'post'
  })
};
/**
 *原材料类型
 */
export const TypeFindAll = (data) => {
  return axios.request({
    url: 'Type/FindAll',
    params: data,
    method: 'post'
  })
};

export const TypeFindByCode = (data) => {
  return axios.request({
    url: 'Type/FindByCode',
    params: data,
    method: 'post'
  })
};

export const TypeInsert = (data) => {
  return axios.request({
    url: 'Type/Insert',
    params: data,
    method: 'post'
  })
};

export const TypeUpdateByCode = (data) => {
  return axios.request({
    url: 'Type/UpdateByCode',
    params: data,
    method: 'post'
  })
};

export const TypeDeleteByCode = (data) => {
  return axios.request({
    url: 'Type/DeleteByCode',
    params: data,
    method: 'post'
  })
};

export const TypeDelete = (data) => {
  return axios.request({
    url: 'Type/Delete',
    params: data,
    method: 'post'
  })
};
/**
 * 原材料材质
 */

export const MaterialQualityFindAll = (data) => {
  return axios.request({
    url: 'MaterialQuality/FindAll',
    params: data,
    method: 'post'
  })
};

export const MaterialQualityFindByCode = (data) => {
  return axios.request({
    url: 'MaterialQuality/FindByCode',
    params: data,
    method: 'post'
  })
};

export const MaterialQualityInsert = (data) => {
  return axios.request({
    url: 'MaterialQuality/Insert',
    params: data,
    method: 'post'
  })
};

export const MaterialQualityUpdateByCode = (data) => {
  return axios.request({
    url: 'MaterialQuality/UpdateByCode',
    params: data,
    method: 'post'
  })
};

export const MaterialQualityDeleteByCode = (data) => {
  return axios.request({
    url: 'MaterialQuality/DeleteByCode',
    params: data,
    method: 'post'
  })
};

export const MaterialQualityDelete = (data) => {
  return axios.request({
    url: 'MaterialQuality/Delete',
    params: data,
    method: 'post'
  })
};

/**
 * 弹簧
 */
export const SpringFindAll = (data) => {
  return axios.request({
    url: 'Spring/FindAll',
    params: data,
    method: 'post'
  })
};

/**
 * 原材料规格
 */
export const SpecificationsFindAll = (data) => {
  return axios.request({
    url: 'Specifications/FindAll',
    params: data,
    method: 'post'
  })
};

export const SpecificationsFindByCode = (data) => {
  return axios.request({
    url: 'Specifications/FindByCode',
    params: data,
    method: 'post'
  })
};

export const SpecificationsInsert = (data) => {
  return axios.request({
    url: 'Specifications/Insert',
    params: data,
    method: 'post'
  })
};

export const SpecificationsUpdateByCode = (data) => {
  return axios.request({
    url: 'Specifications/UpdateByCode',
    params: data,
    method: 'post'
  })
};

export const SpecificationsDeleteByCode = (data) => {
  return axios.request({
    url: 'Specifications/DeleteByCode',
    params: data,
    method: 'post'
  })
};

export const SpecificationsDelete = (data) => {
  return axios.request({
    url: 'Specifications/Delete',
    params: data,
    method: 'post'
  })
};

/**
 * 色号
 */

export const ColorFindAll = (data) => {
  return axios.request({
    url: 'Color/FindAll',
    params: data,
    method: 'post'
  })
};

export const ColorFindByCode = (data) => {
  return axios.request({
    url: 'Color/FindByCode',
    params: data,
    method: 'post'
  })
};

export const ColorInsert = (data) => {
  return axios.request({
    url: 'Color/Insert',
    params: data,
    method: 'post'
  })
};

export const ColorUpdateByCode = (data) => {
  return axios.request({
    url: 'Color/UpdateByCode',
    params: data,
    method: 'post'
  })
};

export const ColorDeleteByCode = (data) => {
  return axios.request({
    url: 'Color/DeleteByCode',
    params: data,
    method: 'post'
  })
};

export const ColorDelete = (data) => {
  return axios.request({
    url: 'Color/Delete',
    params: data,
    method: 'post'
  })
};

/**
 *颜色
 */
export const ColourFindAll = (data) => {
  return axios.request({
    url: 'Colour/FindAll',
    params: data,
    method: 'post'
  })
};

export const ColourFindByCode = (data) => {
  return axios.request({
    url: 'Colour/FindByCode',
    params: data,
    method: 'post'
  })
};

export const ColourInsert = (data) => {
  return axios.request({
    url: 'Colour/Insert',
    params: data,
    method: 'post'
  })
};

export const ColourUpdateByCode = (data) => {
  return axios.request({
    url: 'Colour/UpdateByCode',
    params: data,
    method: 'post'
  })
};

export const ColourDeleteByCode = (data) => {
  return axios.request({
    url: 'Colour/DeleteByCode',
    params: data,
    method: 'post'
  })
};

export const ColourDelete = (data) => {
  return axios.request({
    url: 'Colour/Delete',
    params: data,
    method: 'post'
  })
};

/**
 *香味
 */
export const AromaFindAll = (data) => {
  return axios.request({
    url: 'Aroma/FindAll',
    params: data,
    method: 'post'
  })
};

export const AromaFindByCode = (data) => {
  return axios.request({
    url: 'Aroma/FindByCode',
    params: data,
    method: 'post'
  })
};

export const AromaInsert = (data) => {
  return axios.request({
    url: 'Aroma/Insert',
    params: data,
    method: 'post'
  })
};

export const AromaUpdateByCode = (data) => {
  return axios.request({
    url: 'Aroma/UpdateByCode',
    params: data,
    method: 'post'
  })
};

export const AromaDeleteByCode = (data) => {
  return axios.request({
    url: 'Aroma/DeleteByCode',
    params: data,
    method: 'post'
  })
};

export const AromaDelete = (data) => {
  return axios.request({
    url: 'Aroma/Delete',
    params: data,
    method: 'post'
  })
};


/**
 *厂家
 */
export const ManufactorFindAll = (data) => {
  return axios.request({
    url: 'Manufactor/FindAll',
    params: data,
    method: 'post'
  })
};

export const ManufactorFindByCode = (data) => {
  return axios.request({
    url: 'Manufactor/FindByCode',
    params: data,
    method: 'post'
  })
};

export const ManufactorInsert = (data) => {
  return axios.request({
    url: 'Manufactor/Insert',
    params: data,
    method: 'post'
  })
};

export const ManufactorUpdateByCode = (data) => {
  return axios.request({
    url: 'Manufactor/UpdateByCode',
    params: data,
    method: 'post'
  })
};

export const ManufactorDeleteByCode = (data) => {
  return axios.request({
    url: 'Manufactor/DeleteByCode',
    params: data,
    method: 'post'
  })
};

export const ManufactorDelete = (data) => {
  return axios.request({
    url: 'Manufactor/Delete',
    params: data,
    method: 'post'
  })
};

/**
 *型号
 */
export const ModelFindAll = (data) => {
  return axios.request({
    url: 'Model/FindAll',
    params: data,
    method: 'post'
  })
};

export const ModelFindByCode = (data) => {
  return axios.request({
    url: 'Model/FindByCode',
    params: data,
    method: 'post'
  })
};

export const ModelInsert = (data) => {
  return axios.request({
    url: 'Model/Insert',
    params: data,
    method: 'post'
  })
};

export const ModelUpdateByCode = (data) => {
  return axios.request({
    url: 'Model/UpdateByCode',
    params: data,
    method: 'post'
  })
};

export const ModelDeleteByCode = (data) => {
  return axios.request({
    url: 'Model/DeleteByCode',
    params: data,
    method: 'post'
  })
};


export const ModelDelete = (data) => {
  return axios.request({
    url: 'Model/Delete',
    params: data,
    method: 'post'
  })
};
/**
 *包装
 */
export const PackingFindAll = (data) => {
  return axios.request({
    url: 'Packing/FindAll',
    params: data,
    method: 'post'
  })
};

export const PackingFindByCode = (data) => {
  return axios.request({
    url: 'Packing/FindByCode',
    params: data,
    method: 'post'
  })
};

export const PackingInsert = (data) => {
  return axios.request({
    url: 'Packing/Insert',
    params: data,
    method: 'post'
  })
};

export const PackingUpdateByCode = (data) => {
  return axios.request({
    url: 'Packing/UpdateByCode',
    params: data,
    method: 'post'
  })
};

export const PackingDeleteByCode = (data) => {
  return axios.request({
    url: 'Packing/DeleteByCode',
    params: data,
    method: 'post'
  })
};

export const PackingDelete = (data) => {
  return axios.request({
    url: 'Packing/Delete',
    params: data,
    method: 'post'
  })
};
/**
 * 半成品类型
 */
export const SemiTypeFindAll = (data) => {
  return axios.request({
    url: 'SemiType/FindAll',
    params: data,
    method: 'post'
  })
};

export const SemiTypeFindByCode = (data) => {
  return axios.request({
    url: 'SemiType/FindByCode',
    params: data,
    method: 'post'
  })
};

export const SemiTypeInsert = (data) => {
  return axios.request({
    url: 'SemiType/Insert',
    params: data,
    method: 'post'
  })
};

export const SemiTypeUpdateByCode = (data) => {
  return axios.request({
    url: 'SemiType/UpdateByCode',
    params: data,
    method: 'post'
  })
};

export const SemiTypeDeleteByCode = (data) => {
  return axios.request({
    url: 'SemiType/DeleteByCode',
    params: data,
    method: 'post'
  })
};

export const SemiTypeDelete = (data) => {
  return axios.request({
    url: 'SemiType/Delete',
    params: data,
    method: 'post'
  })
};


/**
 * 原材料编码
 */
export const RawMaterialFindAll = (data) => {
  return axios.request({
    url: 'RawMaterial/FindAll',
    params: data,
    method: 'post'
  })
};

export const RawMaterialFindById = (data) => {
  return axios.request({
    url: 'RawMaterial/FindById',
    params: data,
    method: 'post'
  })
};

export const RawMaterialInsert = (data) => {
  return axios.request({
    url: 'RawMaterial/Insert',
    params: data,
    method: 'post'
  })
};

export const RawMaterialUpdateById = (data) => {
  return axios.request({
    url: 'RawMaterial/UpdateById',
    params: data,
    method: 'post'
  })
};

export const RawMaterialDeleteById = (data) => {
  return axios.request({
    url: 'RawMaterial/DeleteById',
    params: data,
    method: 'post'
  })
};

export const RawMaterialAltogether = (data) => {
  return axios.request({
    url: 'RawMaterial/Altogether',
    params: data,
    method: 'post'
  })
};

/**
 * 半成品编码
 */
export const SemiProductsFindAll = (data) => {
  return axios.request({
    url: 'SemiProducts/FindAll',
    params: data,
    method: 'post'
  })
};

export const SemiProductsFindById = (data) => {
  return axios.request({
    url: 'SemiProducts/FindById',
    params: data,
    method: 'post'
  })
};

export const SemiProductsInsert = (data) => {
  return axios.request({
    url: 'SemiProducts/Insert',
    params: data,
    method: 'post'
  })
};

export const SemiProductsUpdateById = (data) => {
  return axios.request({
    url: 'SemiProducts/UpdateById',
    params: data,
    method: 'post'
  })
};

export const SemiProductsDeleteById = (data) => {
  return axios.request({
    url: 'SemiProducts/DeleteById',
    params: data,
    method: 'post'
  })
};

export const SemiProductsAltogether = (data) => {
  return axios.request({
    url: 'SemiProducts/Altogether',
    params: data,
    method: 'post'
  })
};

/**
 * 成品编码
 */
export const ProductFindAll = (data) => {
  return axios.request({
    url: 'Product/FindAll',
    params: data,
    method: 'post'
  })
};

export const ProductFindById = (data) => {
  return axios.request({
    url: 'Product/FindById',
    params: data,
    method: 'post'
  })
};

export const ProductUpdateById = (data) => {
  return axios.request({
    url: 'Product/UpdateById',
    params: data,
    method: 'post'
  })
};

export const ProductInsert = (data) => {
  return axios.request({
    url: 'Product/Insert',
    params: data,
    method: 'post'
  })
};

export const ProductDeleteById = (data) => {
  return axios.request({
    url: 'Product/DeleteById',
    params: data,
    method: 'post'
  })
};

export const ProductAltogether = (data) => {
  return axios.request({
    url: 'Product/Altogether',
    params: data,
    method: 'post'
  })
};

/**
 * 物料仓库
 */
export const MaterialWarehouseFindAll = (data) => {
  return axios.request({
    url: 'MaterialWarehouse/FindAll',
    params: data,
    method: 'post'
  })
};

/**
 *半成品库
 */
export const SemiProductWarehouseFindAll = (data) => {
  return axios.request({
    url: 'SemiProductWarehouse/FindAll',
    params: data,
    method: 'post'
  })
};

/**
 * 原材料出入库/半成品出入库
 */
export const InOutWarehouseFindAll = (data) => {
  return axios.request({
    url: 'InOutWarehouse/FindAll',
    params: data,
    method: 'post'
  })
};

/**
 * WIP
 */
export const WIPFindAll = (data) => {
  return axios.request({
    url: 'WIP/FindAll',
    params: data,
    method: 'post'
  })
};
//最终半成品
export const SemiProductUltimateFindAll = (data) => {
  return axios.request({
    url: 'SemiProductUltimate/FindAll',
    params: data,
    method: 'post'
  })
};
export  const ProductAndProcessFindAll = (data) => {
  return axios.request({
    url: 'ProductAndProcessFindAll',
    params: data,
    method: 'post'
  })
};




export const exportExcel = (url, data) => {
  window.location.href = axios.baseUrl + url + "?" + formateObjToParamStr(data);
};

function filter(str) { // 特殊字符转义
  str += ''; // 隐式转换
  str = str.replace(/%/g, '%25');
  str = str.replace(/\+/g, '%2B');
  str = str.replace(/ /g, '%20');
  str = str.replace(/\//g, '%2F');
  str = str.replace(/\?/g, '%3F');
  str = str.replace(/&/g, '%26');
  str = str.replace(/\=/g, '%3D');
  str = str.replace(/#/g, '%23');
  return str;
}

function formateObjToParamStr(paramObj) {
  const sdata = [];
  for (let attr in paramObj) {
    if (!!paramObj[attr]) {
      sdata.push(`${attr}=${filter(paramObj[attr])}`);
    } else {
      sdata.push(`${attr}=${filter('')}`);
    }

  }
  return sdata.join('&');
};
